package com.study.business.controller.admin;

import com.study.server.domain.Chapter;
import com.study.server.dto.ChapterDto;
import com.study.server.dto.PageDto;
import com.study.server.dto.ResponseDto;
import com.study.server.exception.ValidatorException;
import com.study.server.service.ChapterService;
import com.study.server.util.ValidatorUtil;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/admin/chapter" )
public class ChapterController {
    private static final Logger LOG = LoggerFactory.getLogger(ChapterController.class);
    public static final String BUSINESS_NAME = "大章";
    @Resource
    private ChapterService service;


    /**
     * 查询
     * @param pageDto
     * @return
     */

   @RequestMapping(value = "/list" )
   public ResponseDto get(@RequestBody PageDto pageDto){
       ResponseDto objectResponseDto = new ResponseDto();
       System.out.println("pageDto {}"+pageDto);
        service.list(pageDto);
       objectResponseDto.setContent(pageDto);
     return objectResponseDto;
   }

    /**
     * 保存
     * @param chapterDto
     * @return
     */
   @RequestMapping(value = "/save")
   public ResponseDto save(@RequestBody ChapterDto chapterDto){

            ValidatorUtil.require(chapterDto.getName(),"，课程");
            ValidatorUtil.require(chapterDto.getCourseId(),"，课程ID");
            ValidatorUtil.length(chapterDto.getCourseId(),"，课程ID",1,8);


       ResponseDto objectResponseDto = new ResponseDto();
       System.out.println("chapterDto {}"+chapterDto);
      service.save(chapterDto);
       objectResponseDto.setContent(chapterDto);
     return objectResponseDto;

   }


    /**
     * 删除
     * @param
     * @return
     */
   @DeleteMapping(value = "/del/{id}")
   public ResponseDto del(@PathVariable String id){
       ResponseDto objectResponseDto = new ResponseDto();
       System.out.println("id {}"+id);
      service.del(id);

     return objectResponseDto;

   }
}
